home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / include / elements / CEGUIPushButton.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-02  |  11.5 KB  |  336 lines

  1. /************************************************************************
  2.     filename:     CEGUIPushButton.h
  3.     created:    13/4/2004
  4.     author:        Paul D Turner
  5.     
  6.     purpose:    Interface to base class for PushButton widget
  7. *************************************************************************/
  8. /*************************************************************************
  9.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  10.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  11.  
  12.     This library is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU Lesser General Public
  14.     License as published by the Free Software Foundation; either
  15.     version 2.1 of the License, or (at your option) any later version.
  16.  
  17.     This library is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.     Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public
  23.     License along with this library; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. *************************************************************************/
  26. #ifndef _CEGUIPushButton_h_
  27. #define _CEGUIPushButton_h_
  28.  
  29. #include "CEGUIBase.h"
  30. #include "elements/CEGUIButtonBase.h"
  31. #include "elements/CEGUIPushButtonProperties.h"
  32. #include "CEGUIRenderableImage.h"
  33.  
  34. #if defined(_MSC_VER)
  35. #    pragma warning(push)
  36. #    pragma warning(disable : 4251)
  37. #endif
  38.  
  39. // Start of CEGUI namespace section
  40. namespace CEGUI
  41. {
  42. /*!
  43. \brief
  44.     Base class to provide logic for push button type widgets.
  45. */
  46. class CEGUIEXPORT PushButton : public ButtonBase
  47. {
  48. public:
  49.     static const String EventNamespace;                //!< Namespace for global events
  50.  
  51.  
  52.     /*************************************************************************
  53.         Event name constants
  54.     *************************************************************************/
  55.     // generated internally by Window
  56.     static const String EventClicked;                    //!< The button was clicked.
  57.  
  58.     /*************************************************************************
  59.         Construction and Destruction
  60.     *************************************************************************/
  61.     /*!
  62.     \brief
  63.         Constructor for base PushButton class
  64.     */
  65.     PushButton(const String& type, const String& name);
  66.  
  67.  
  68.     /*!
  69.     \brief
  70.         Destructor for PushButton class
  71.     */
  72.     virtual ~PushButton(void);
  73.  
  74.     /*************************************************************************
  75.         Common Public Interface
  76.     *************************************************************************/
  77.     /*!
  78.     \brief
  79.         return whether or not rendering of the standard imagery is enabled.
  80.  
  81.     \return
  82.         true if the standard button imagery will be rendered, false if no standard rendering will be performed.
  83.     */
  84.     bool    isStandardImageryEnabled(void) const;
  85.  
  86.  
  87.     /*!
  88.     \brief
  89.         Return whether of not custom button image areas are auto-scaled to the size of the button.
  90.  
  91.     \return
  92.         true if client specified custom image areas are re-sized when the button size changes.  false if image areas will
  93.         remain unchanged when the button is sized.
  94.     */
  95.     bool    isCustomImageryAutoSized(void) const;
  96.  
  97.     /*!
  98.     \brief
  99.         returns a pointer to a read-only RenderableImage object holding the details
  100.         of the image set to render for the button in the normal state, or 0 if no
  101.         image is currently set for this state.
  102.  
  103.     \return
  104.         Pointer to a const RenderableImage object with all the details for the image.  
  105.     */
  106.     const RenderableImage*    getNormalImage(void) const;
  107.  
  108.     /*!
  109.     \brief
  110.         returns a pointer to a read-only RenderableImage object holding the details
  111.         of the image set to render for the button in the highlighted state, or 0 if no
  112.         image is currently set for this state.
  113.  
  114.     \return
  115.         Pointer to a const RenderableImage object with all the details for the image.  
  116.     */
  117.     const RenderableImage*    getHoverImage(void) const;
  118.  
  119.     /*!
  120.     \brief
  121.         returns a pointer to a read-only RenderableImage object holding the details
  122.         of the image set to render for the button in the pushed state, or 0 if no
  123.         image is currently set for this state.
  124.  
  125.     \return
  126.         Pointer to a const RenderableImage object with all the details for the image.  
  127.     */
  128.     const RenderableImage*    getPushedImage(void) const;
  129.  
  130.     /*!
  131.     \brief
  132.         returns a pointer to a read-only RenderableImage object holding the details
  133.         of the image set to render for the button in the disabled state, or 0 if no
  134.         image is currently set for this state.
  135.  
  136.     \return
  137.         Pointer to a const RenderableImage object with all the details for the image.  
  138.     */
  139.     const RenderableImage*    getDisabledImage(void) const;
  140.  
  141.     /*!
  142.     \brief
  143.         get the offset that is used to shift of the text in the x-direction
  144.         this is useful if the button-images are not symmetrical and the
  145.         text shouldn't be completely centered
  146.  
  147.     \return
  148.         the offset relative to the button-size
  149.     */
  150.     float   getTextXOffset(void) const;
  151.  
  152.     /*!
  153.     \brief
  154.         set whether or not to render the standard imagery for the button
  155.  
  156.     \param setting
  157.         true to have the standard button imagery drawn, false to have no standard imagery drawn.
  158.  
  159.     \return
  160.         Nothing.
  161.     */
  162.     void    setStandardImageryEnabled(bool setting);
  163.  
  164.     /*!
  165.     \brief
  166.         Set whether to auto re-size custom image areas when the button is sized.
  167.  
  168.     \param setting
  169.         true to have custom image areas auto-sized.  false to have system leave image areas untouched.
  170.  
  171.     \return
  172.         Nothing.
  173.     */
  174.     void    setCustomImageryAutoSized(bool setting);
  175.  
  176.     /*!
  177.     \brief
  178.         set the details of the image to render for the button in the normal state.
  179.  
  180.     \param image
  181.         RenderableImage object with all the details for the image.  Note that an internal copy of the Renderable image is made and
  182.         ownership of \a image remains with client code.  If this parameter is NULL, rendering of an image for this button state is
  183.         disabled.
  184.  
  185.     \return
  186.         Nothing.
  187.     */
  188.     void    setNormalImage(const RenderableImage* image);
  189.  
  190.     /*!
  191.     \brief
  192.         set the details of the image to render for the button in the highlighted state.
  193.  
  194.     \param image
  195.         RenderableImage object with all the details for the image.  Note that an internal copy of the Renderable image is made and
  196.         ownership of \a image remains with client code.  If this parameter is NULL, rendering of an image for this button state is
  197.         disabled.
  198.  
  199.     \return
  200.         Nothing.
  201.     */
  202.     void    setHoverImage(const RenderableImage* image);
  203.  
  204.     /*!
  205.     \brief
  206.         set the details of the image to render for the button in the pushed state.
  207.  
  208.     \param image
  209.         RenderableImage object with all the details for the image.  Note that an internal copy of the Renderable image is made and
  210.         ownership of \a image remains with client code.  If this parameter is NULL, rendering of an image for this button state is
  211.         disabled.
  212.  
  213.     \return
  214.         Nothing.
  215.     */
  216.     void    setPushedImage(const RenderableImage* image);
  217.  
  218.     /*!
  219.     \brief
  220.         set the details of the image to render for the button in the disabled state.
  221.  
  222.     \param image
  223.         RenderableImage object with all the details for the image.  Note that an internal copy of the Renderable image is made and
  224.         ownership of \a image remains with client code.  If this parameter is NULL, rendering of an image for this button state is
  225.         disabled.
  226.  
  227.     \return
  228.         Nothing.
  229.     */
  230.     void    setDisabledImage(const RenderableImage* image);
  231.  
  232.     /*!
  233.     \brief
  234.         set the offset to use for a shift of the text in the x-direction
  235.         this is useful if the button-images are not symmetrical and the
  236.         text shouldn't be completely centered
  237.  
  238.     \param offset
  239.         The offset to use. This is relative to the button-width
  240.  
  241.     \return
  242.         Nothing.
  243.     */
  244.     void   setTextXOffset(float offset);
  245.  
  246. protected:
  247.     /*************************************************************************
  248.         New Event Handlers
  249.     *************************************************************************/
  250.     /*!
  251.     \brief
  252.         handler invoked internally when the button is clicked.
  253.     */
  254.     virtual void    onClicked(WindowEventArgs& e);
  255.  
  256.  
  257.     /*************************************************************************
  258.         Overridden Event Handlers
  259.     *************************************************************************/
  260.     virtual void    onMouseButtonUp(MouseEventArgs& e);
  261.     virtual void    onSized(WindowEventArgs& e);
  262.  
  263.  
  264.     /*************************************************************************
  265.         Implementation Functions
  266.     *************************************************************************/
  267.     /*!
  268.     \brief
  269.         Add button specific events
  270.     */
  271.     void    addPushButtonEvents(void);
  272.  
  273.  
  274.     /*!
  275.     \brief
  276.         Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
  277.  
  278.     \param class_name
  279.         The class name that is to be checked.
  280.  
  281.     \return
  282.         true if this window was inherited from \a class_name. false if not.
  283.     */
  284.     virtual bool    testClassName_impl(const String& class_name) const
  285.     {
  286.         if (class_name==(const utf8*)"PushButton")    return true;
  287.         return ButtonBase::testClassName_impl(class_name);
  288.     }
  289.  
  290.  
  291.     /*************************************************************************
  292.         Data Fields
  293.     *************************************************************************/
  294.     // flags stating which imagery is to be rendered and how.
  295.     bool    d_autoscaleImages;                //!< when true custom images will be scaled to the same size as the button
  296.     bool    d_useStandardImagery;            //!< true if button standard imagery should be drawn.
  297.     bool    d_useNormalImage;                //!< true if an image should be drawn for the normal state.
  298.     bool    d_useHoverImage;                //!< true if an image should be drawn for the highlighted state.
  299.     bool    d_usePushedImage;                //!< true if an image should be drawn for the pushed state.
  300.     bool    d_useDisabledImage;                //!< true if an image should be drawn for the disabled state.
  301.  
  302.     // button RenderableImage objects
  303.     RenderableImage        d_normalImage;        //!< RenderableImage used when rendering an image in the normal state.
  304.     RenderableImage        d_hoverImage;        //!< RenderableImage used when rendering an image in the highlighted state.
  305.     RenderableImage        d_pushedImage;        //!< RenderableImage used when rendering an image in the pushed state.
  306.     RenderableImage        d_disabledImage;    //!< RenderableImage used when rendering an image in the disabled state.
  307.  
  308.     //text-offset
  309.     float d_textXOffset;        //!< offset applied to the x co-ordinate of the text label.
  310.  
  311. private:
  312.     /*************************************************************************
  313.         Static Properties for this class
  314.     *************************************************************************/
  315.     static PushButtonProperties::NormalImage    d_normalImageProperty;
  316.     static PushButtonProperties::PushedImage    d_pushedImageProperty;
  317.     static PushButtonProperties::HoverImage     d_hoverImageProperty;
  318.     static PushButtonProperties::DisabledImage  d_disabledImageProperty;
  319.     static PushButtonProperties::UseStandardImagery d_useStandardImageryProperty;
  320.     static PushButtonProperties::TextXOffset    d_textXOffsetProperty;
  321.  
  322.     /*************************************************************************
  323.         Private methods
  324.     *************************************************************************/
  325.     void    addPushButtonProperties(void);
  326. };
  327.  
  328.  
  329. } // End of  CEGUI namespace section
  330.  
  331. #if defined(_MSC_VER)
  332. #    pragma warning(pop)
  333. #endif
  334.  
  335. #endif    // end of guard _CEGUIPushButton_h_
  336.